package com.xxl.job.executor.service.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;

public class HttpUtilService {
	
	
	public String queryUrl(String api, Map<String, String>map)
	{
		Runnable run = new myRunnalbe();
		Thread thread = new Thread(run);  
        thread.start();
		return "";
	}
	
	private class myRunnalbe implements Runnable
	{
		private String api;
		private HashMap<String, String> param;
		private String encode = "utf8";
		
		public void myRunnable(String api, Map<String, String>map)
		{
			this.api = api;
			this.param = (HashMap) map;
		}
		
		public void myRunnable(String api, Map<String, String>map, String encode)
		{
			this.api = api;
			this.param = (HashMap) map;
			this.encode = encode;
		}
		
		@Override
        public void run() {  
			
			HttpClient httpclient = HttpClients.createDefault();  
			HttpPost httppost = new HttpPost(api);
			List<NameValuePair> nameValue = new ArrayList<NameValuePair>();
			for(String k :  param.keySet())
			{
				nameValue.add(new BasicNameValuePair(k, param.get(k)));
			}
			try {  
			      httppost.setEntity(new UrlEncodedFormEntity(nameValue, encode));  
			      HttpResponse response = httpclient.execute(httppost);  
			} catch (Exception e) {
				 
			}
		}
	}	
	
}
